package com.jhy.study2;

import java.util.*;

/**
 * @author: robert
 * @description: Set的一些测试
 * @date: 2021/8/23 15:18
 * @return
 */
public class SetTestor1 {
    public static void main(String[] args) {
        testHashSet();
        System.out.println("=========================");
        testLinkedHashSet();
        System.out.println("=========================");
        testTreeSet();


    }
    public static void testHashSet(){
        Set<String> set1 = new HashSet<>();
        set1.add("ddd");
        set1.add("bb");
        set1.add("ba");
        set1.add("bb");
        set1.add("aaa");
        set1.add("");
        set1.add(null);
//        set1.remove("bb");

        System.out.println("size:"+set1.size());
        System.out.println(set1.contains("aada"));
        for(String s: set1){
            System.out.println(s);
        }

    }


    public static void testLinkedHashSet(){
        Set<String> set1 = new LinkedHashSet<>();
        set1.add("ddd");
        set1.add("bb");
        set1.add("ba");
        set1.add("bb");
        set1.add("aaa");
        set1.add("");
        set1.add(null);
//        set1.remove("bb");

        for(String s: set1){
            System.out.println(s);
        }

    }


    public static void testTreeSet(){
        Set<String> set1 = new TreeSet<>(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {   //果然好使
                return o2.compareTo(o1);
            }
        });
        set1.add("ddd");
        set1.add("bb");
        set1.add("ba");
        set1.add("bb");
        set1.add("aaa");
        set1.add("");
//        set1.add(null);  //treese不能添加null
//        set1.remove("bb");

        for(String s: set1){
            System.out.println(s);
        }

    }

}
